package com.example.tbplus14.Test;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class GenericTest {

    public static <A extends Collection<E>, B extends Collection<E>, E> int totalSize(A a, B b) {
        return a.size() + b.size();
    }

    public static void printNumbers(List<? super Integer> numbers) {
        numbers.forEach(System.out::println);
    }

    public static void testFS()throws Exception{
        // 正常创建一个整数型集合，并添加一个元素
        List<Integer> list = new ArrayList<>();
        list.add(123);

// 通过反射机制强行调用add()方法塞入字符串
        Method add = list.getClass().getMethod("add", Object.class);
        add.invoke(list, "竹子爱熊猫");

// 遍历list集合并输出所有元素
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        for (Integer integer : list) {
            System.out.println(integer);
        }



    }

    public static void main(String[] args) throws Exception{
        System.out.println(totalSize(Collections.emptyList(), Collections.emptyList()));
        List<Integer> l = new ArrayList<>();
        printNumbers(l);

        testFS();
    }

}
